package com.hclc.impl.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hclc.api.base.IBaseSmsLogService;
import com.hclc.entity.model.BaseSmsLogModel;
import com.hclc.mapper.base.BaseSmsLogMapper;
import com.hclc.util.json.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * <p>短信日志 服务实现类 </p>
 *
 * @author lx(1309244704 @ qq.com)
 * @since 2019-08-28
 */
@Service("baseSmsLogService")
public class BaseSmsLogServiceImpl extends ServiceImpl<BaseSmsLogMapper, BaseSmsLogModel> implements IBaseSmsLogService {

    private static Logger _logger = LoggerFactory.getLogger(BaseSmsLogServiceImpl.class);

    private @Autowired
    BaseSmsLogMapper baseSmsLogMapper;

    /**
     * 查询状态并分页
     */
    @Override
    public IPage<BaseSmsLogModel> getPage(Page<BaseSmsLogModel> page, Map<String, Object> map)  {
        IPage<BaseSmsLogModel> resultPage = baseSmsLogMapper.selectPage(page, new QueryWrapper<BaseSmsLogModel>().allEq(map, false));
        return resultPage;
    }

    /**
     * 插入
     */
    @Transactional
    @Override
    public void addBaseSmsLog(BaseSmsLogModel model) {
        Assert.notNull(model, "model is null");
        _logger.debug("BaseSmsLogModel = {}", JsonUtil.toJson(model));
        baseSmsLogMapper.insert(model);
    }

    /**
     * 修改
     */
    @Transactional
    @Override
    public void modBaseSmsLog(BaseSmsLogModel model) {
        Assert.notNull(model, "model is null");
        _logger.debug("BaseSmsLogModel = {}", JsonUtil.toJson(model));
        baseSmsLogMapper.updateById(model);
    }

    /**
     * 删除状态（物理删除）
     */
    @Transactional
    @Override
    public void del(Long id)  {
        Assert.notNull(id, "id is null");
        _logger.debug("id = {}", id);
        baseSmsLogMapper.deleteById(id);
    }
}
